package com.popo.android.widget;

import android.app.Activity;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import android.graphics.RectF;

import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.GestureDetector.OnGestureListener;

public class MyPathWheelView extends View implements Runnable,OnGestureListener {
	Paint paint = new Paint();
	Paint mFramePaint;
	int start = 0;
	RectF rectF;

	Boolean Running = false;
	private int speedstep;
	private long sleeptime;

	public MyPathWheelView(Activity activity) {
		super(activity);
		// TODO Auto-generated constructor stub

		paint.setColor(Color.RED);
		paint.setAntiAlias(true);

		mFramePaint = new Paint();
		mFramePaint.setColor(Color.BLACK);
		mFramePaint.setAntiAlias(true);
		mFramePaint.setStyle(Paint.Style.STROKE);
		mFramePaint.setStrokeWidth(0);
		rectF = new RectF(40, 40, 200, 200);
		speedstep=20;
		sleeptime=20;
		Running=false;
		new Thread(this).start();

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.view.View#onDraw(android.graphics.Canvas)
	 */
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		Log.v("msg", "hello" + start);
		canvas.drawColor(Color.WHITE);
		paint.setColor(Color.RED);
		canvas.drawArc(rectF, start, 92, true, paint);
		paint.setColor(Color.BLUE);
		canvas.drawArc(rectF, 90 + start, 92, true, paint);
		paint.setColor(Color.RED);
		canvas.drawArc(rectF, 180 + start, 92, true, paint);
		paint.setColor(Color.BLUE);
		canvas.drawArc(rectF, 270 + start, 92, true, paint);

	}
	
	
	
	/* (non-Javadoc)
	 * @see android.view.View#onTouchEvent(android.view.MotionEvent)
	 */
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		//return super.onTouchEvent(event);	}
		float x = event.getX();
		float y = event.getY();
		switch(event.getAction()){
		case MotionEvent.ACTION_DOWN:
			
		}
		
		return true;
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (true) {
			try {
				Thread.sleep(sleeptime);
				if (Running == true) {
					start += speedstep;
					if (start == 360) {
						start = 0;
					}
					this.postInvalidate();
				}
			} catch (Exception e) {
				// TODO: handle exception
			}
		}

	}

	@Override
	public boolean onDown(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void onLongPress(MotionEvent e) {
		// TODO Auto-generated method stub
		Log.v("msg","onLongPress["+e.getAction()+"]");
		
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		// TODO Auto-generated method stub
		Log.v("msg","onScroll [e1:"+e1.getX()+","+e1.getY()+"],[e2:"+e2.getX()+","+e2.getY()+"],distanceX["+distanceX+"],distanceY["+distanceY+"]");
		return false;
	}

	@Override
	public void onShowPress(MotionEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

}
